<?php
namespace catchAdmin\home\controller;

use catcher\CatchResponse;
use catcher\base\CatchRequest;
use catcher\base\CatchController;
use app\common\model\Follow as FollowModel;
use app\common\model\PropagandaEducationHistory as EdHModel;
use app\common\model\Contract as ContractModel;
use app\common\model\PatientInfo as PatientInfoModel;
use app\common\model\PushMessage as PushMessageModel;
use catchAdmin\visitPlan\model\VisitPlanDetail as VisitPlanDetailModel;
use catchAdmin\home\service\HomeService;

class Homepage extends CatchController
{
    /**
     * 统计
     *
     * @time 2020年01月09日
     * @return \think\response\Json
     */
    public function statistics(): \think\response\Json
    {
        $user_id = request()->user()->id;
        $follow = (new FollowModel)->getStaffFollow($user_id);
        $ed = (new EdHModel)->getCreatorEd($user_id);
        $contract = (new ContractModel)->getDoctorContract($user_id);
        $statistics['follow'] = $follow;
        $statistics['ed'] = $ed;
        $statistics['contract'] = $contract;
        return CatchResponse::success($statistics);
    }

    /**
     * 任务中心
     *
     * @time 2020年01月09日
     * @return \think\response\Json
     */
    public function followtask(): \think\response\Json
    {
        $user_id = request()->user()->id;
        $list = (new FollowModel)->getGztList($user_id);
        return CatchResponse::success($list);
    }

    /**
     * 异常患者
     *
     * @time 2020年01月09日
     * @return \think\response\Json
     */
    public function diepatient(): \think\response\Json
    {
        return CatchResponse::success((new PatientInfoModel)->getDoctorDie());
    }

    /**
     * 消息
     *
     * @time 2020年01月09日
     * @return \think\response\Json
     */
    public function news(): \think\response\Json
    {
        $doctor_id = request()->user()->id;
        return CatchResponse::success((new PushMessageModel)->getFollowMessge($doctor_id));
    }

    /**
     * 复诊计划
     *
     * @time 2020年01月09日
     * @return \think\response\Json
     */
    public function visit(): \think\response\Json
    {
        return CatchResponse::success((new VisitPlanDetailModel)->getHomeList());
    }

    /**
     *------------------------------------------------------------------------------------------------
     */

    /**
     * 顶部信息
     * @return \think\response\Json
     */
    public function currentDoctor(): \think\response\Json
    {
        $user = request()->user();
        return CatchResponse::success((new HomeService())->getHomeHerd($user['id'], (string)$user['doctor_code']));
    }

    /**
     * 待办事项
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function stagingBacklog(CatchRequest $request): \think\response\Json
    {
        $req = $request->param();
        $user = request()->user();
        if (!isset($req['type']) || $req['type'] == 'undefined') {
            $req['type'] = 1;
        }
	//return CatchResponse::success();
       return CatchResponse::success((new HomeService())->getToDoList($user['id'], (string)$user['doctor_code'], $req['type']));
    }

    /**
     * 随访任务
     * @return \think\response\Json
     */
    public function rollFollowTask(): \think\response\Json
    {
        $user = request()->user();
        return CatchResponse::success((new HomeService())->getFollowTask((string)$user['doctor_code']));
    }

    /**
     * 随访情况分析
     * @return \think\response\Json
     */
    public function followCaseAnalysis(): \think\response\Json
    {
        $user = request()->user();
        return CatchResponse::success((new HomeService())->getFollowCaseAnalysis((string)$user['doctor_code']));
    }

    /**
     * 随访趋势分析
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function followTrendAnalysis(CatchRequest $request): \think\response\Json
    {
        $req = $request->param();
        $user = request()->user();
        if (!isset($req['type']) || $req['type'] == 'undefined') {
            $req['type'] = 1;
        }
	//return CatchResponse::success();
        return CatchResponse::success((new HomeService())->getFollowTrendAnalysis((string)$user['doctor_code'],$req['type']));
    }
}
